package Swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DialogDemo extends JFrame {
    //构造器
    public DialogDemo()  {
        this.setVisible(true);
        this.setSize(700,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭事件
        //JFrame放东西，放在容器里
        Container contentPane = this.getContentPane();
        //绝对布局，通过这是窗口中的坐标进行定位
        contentPane.setLayout(null);

        //按钮
        JButton jButton = new JButton("点击弹出一个对话框");
        jButton.setBounds(10,20,200,50);//绝对布局方式
        //对按钮添加监听事件
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MyDialogDemo();
            }
        });
        contentPane.add(jButton);
    }

    public static void main(String[] args) {
        new DialogDemo();
    }
}
class MyDialogDemo extends JDialog{
    public MyDialogDemo() {
        this.setVisible(true);
        this.setBounds(50,50,500,500);
//        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);弹窗可以关掉，不用加这句话

        Container container = this.getContentPane();
        container.setLayout(null);//绝对布局
        super.add(new Label("This is a DialogWindow"));
    }
}